package cn.tedu._03vehicle.base.interceptor;

import cn.tedu._03vehicle.pojo.entity.User;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

@Slf4j
public class LoginCheckInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("登录检查拦截器的preHandle");
        User user = (User)request.getSession().getAttribute("user");
        if (user == null) {
            //重定向到登录页面
            response.sendRedirect("/login.html");
        }
        return true;
    }
}
